package org.sbbs.base.demo.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.Index;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
import org.hibernate.envers.AuditOverride;
import org.hibernate.envers.Audited;
import org.hibernate.envers.NotAudited;
import org.sbbs.base.jpa.entity.BaseAuditTreeEntity;

/**
 * @author jenkins
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Audited
@AuditOverride(forClass = BaseAuditTreeEntity.class, isAudited = true)
//@EntityListeners({AuditingEntityListener.class})
@Table(name = "base_tree_audit",
        indexes = {
            @Index(name = "idx_pid_fk", columnList = "pid")
        })
@Comment("树样例表")
public class BaseTreeBeanAudit extends BaseAuditTreeEntity {

    @NotAudited
    @Formula("(select count(1)>0 from base_tree t where t.pid=id)")
    private boolean hasChildren;

    @Transient
    private boolean leaf = false;

//    @Override
//    public boolean isHasChildren() {
//        throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
//    }
}
